import 'package:flutter/widgets.dart';

class AllLexicalItemPageTranslation {
  static final delegate = _AllLexicalItemPageTranslationDelegate();

  static AllLexicalItemPageTranslation of(BuildContext context) {
    return Localizations.of(context, AllLexicalItemPageTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get title {
    return _resolve(const {
      'ru': 'Все слова',
      'en': 'All words',
    });
  }
}

class _AllLexicalItemPageTranslationDelegate
    extends LocalizationsDelegate<AllLexicalItemPageTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru', 'en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<AllLexicalItemPageTranslation> old) => false;

  @override
  Future<AllLexicalItemPageTranslation> load(Locale locale) async {
    final translation = AllLexicalItemPageTranslation();
    await translation.load(locale);
    return translation;
  }
}
